#if !defined(AFX_MYADDRESSLISTBOX_H__875460F3_957B_11D2_8082_00A0C91F41A7__INCLUDED_)
#define AFX_MYADDRESSLISTBOX_H__875460F3_957B_11D2_8082_00A0C91F41A7__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// MyAddressListBox.h : header file
//

#include "8085Doc.h"
#include "MyTypedef.h"
#include "8085Object.h"
#include "CommonObject.h"
#include "Resource.h"
//#include "ColourText.h"

typedef struct tagOneDisplayElement
{
    int  data;
    int  address;
    BOOL bModified;
    char szMnemonic[32];
}OneDisplayElement;



/////////////////////////////////////////////////////////////////////////////
// CMyAddressListBox window

class CMyAddressListBox : public CListBox, public virtual CCommonObject
{
// Construction
public:
	CMyAddressListBox();
	virtual ~CMyAddressListBox();
	void Init();

// Attributes
public:
// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMyAddressListBox)
	public:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
	virtual int CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct);
	protected:
	virtual void PreSubclassWindow();
	//}}AFX_VIRTUAL

// Implementation
public:
	void CalculateListBoxProperty(RECT &r);

    inline int GetSegmentSize()                 {return Get8085Object()->GetSegmentSize();}
    inline word GetEndAddrInSeg(word addr)      {return Get8085Object()->GetEndAddrInSegment(addr);}
    inline word GetMemSize()					{return Get8085Object()->GetMemSize();}
	inline char * OpcodeToString(word addr,char *szPrefix)		
        {return Get8085Object()->OpcodeToString(addr,szPrefix);}
	inline int GetInstructionLenAt(word addr)	{return Get8085Object()->GetInstructionLenAt(addr);}
	inline byte ReadMemByte(word addr)			{return Get8085Object()->ReadMemByte(addr);}
	inline word ReadMemWord(word addr)			{return Get8085Object()->ReadMemWord(addr);}
	inline void WriteMem(word addr,byte data)   {Get8085Object()->WriteMem(addr,data);}
	inline void WriteMem(word addr,word data)   {Get8085Object()->WriteMem(addr,data);}

    inline word AddressAtIndex(int x)           {return m_aDisplay[x].address;}
    virtual void Refresh();

	void Display();
	virtual int RefreshStrings(int addr=0,BOOL bCheckModified=TRUE);
	//virtual void OnVirtualLButtonDown(UINT nFlags, CPoint point)=0;
	virtual void OnVirtualKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	virtual void OnVirtualLButtonDblClk(UINT nFlags, CPoint point);
	virtual void OnVirtualVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
    virtual void AllocatePrevArray();

    // for movement within the list box using keyboard or mouse
	virtual int GotoAddress();
	virtual int MoveOnePageDown();
	virtual int MoveOnePageUp();
	virtual int MoveToEnd();
	virtual int MoveOneAddressDown();
	virtual int MoveOneAddressUp();
    inline int  GetMaxSize();
    inline void SetMaxSize(int nSize);

// data members
protected:
    int		m_nItemHeight;      // height of each item
    int		m_nItems;           // number of items that can be accomodated in the box
    int		m_nHeight;          // height of the listbox
    int		*m_nPrev;           // used to store the addresses for page up, pagedown etc
    BOOL	m_bRedrawBkgnd;		// should background be redrawn by the OnEraseBkgnd message handler
    int		m_nMarginWidth;     // leave this much space before printing text
    int		m_nPropertySet;		// set to 1 if property has been set
	int		m_nSelectedIndex;	// the selection in the listbox
    word	m_nFirstAddress;	// the first address that is displayed in the listbox
    word	m_nLastAddress;		// the last address displayed in the listbox
    CRect	m_cFrame;			// the original frame received by DrawItem
    CRect	m_cTextFrame;		// the frame to draw the text
	CRect	m_cSelectedFrame;	// the frame of the selected item
    CRect	m_Rect;				// rectangle of the listbox
    OneDisplayElement *m_aDisplay;  // contains the elements to be Displayed in the listbox
    int     m_nLastKey;         // value of the last key pressed
    int     m_nItemsDisplayed;  // number of items actually displayed
    CMenu   m_cMenu;
    // maximum number of elements possible for the list box.
    // This is not the same as the maximum elements that are currently
    // present in the list box, but is something like this
    // max number in a addresslist box is 0xffff, in the case of
    // ports is 0xff
    int     m_nMaxSize;         
    BOOL    m_bShiftDown;       // TRUE if Shift is in depressed state
    BOOL    m_bCtrlDown;        // TRUE if CTRL is in depressed state

public:
	int IndexAtAddress(word nAddress);
	virtual void IncrementData();
	virtual void DecrementData();
	virtual void EnableDisableBkPt();
	virtual void EnableDisableMenuItems();
	virtual int ToggleBreakPoint();
	void EnterValidData();
	virtual void SetIndividualProperty();
	BOOL IsNumber(char *str,int &number);

private:
	virtual void EnterData();


	// Generated message map functions
protected:
	//{{AFX_MSG(CMyAddressListBox)
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnSetFocus(CWnd* pOldWnd);
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnModifyData();
	afx_msg void OnToggleBreakpoint();
	afx_msg void OnEnableDisableBkpt();
	virtual void OnShowSourceLine();
	afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

inline int CMyAddressListBox::GetMaxSize()
{
    return m_nMaxSize;
}

inline void CMyAddressListBox::SetMaxSize(int nSize)
{
    m_nMaxSize=nSize;
}


//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MYADDRESSLISTBOX_H__875460F3_957B_11D2_8082_00A0C91F41A7__INCLUDED_)
